﻿using Chaunce.FrameWork.NetCore.IdentityManager;
using Chaunce.Web.Core.Models;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chaunce.Web.Core.Controllers
{
    public abstract class BaseMvcController : Controller
    {
        protected string UserName
        {
            get
            {
                if (User.Identity.IsAuthenticated)
                {
                    return User.Identity.Name;
                }
                return null;
            }
        }

        /// <summary>
        /// 暂存
        /// </summary>
        private int UserId
        {
            get
            {
                if (User.Identity.IsAuthenticated)
                {
                    return User.Identity.GetUserId<int>();
                }
                return 0;
            }
        }

        /// <summary>
        /// 获取客户端地址
        /// </summary>
        /// <returns></returns>
        public string GetIP()
        {
            return HttpContext.Connection.RemoteIpAddress.ToString();
        }
    }
}

